# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("//bazel:pl_build_system.bzl", "pl_cc_binary", "pl_cc_library", "pl_cc_test")

package(default_visibility = ["//src/carnot:__subpackages__"])

pl_cc_library(
    name = "cc_library",
    srcs = glob(
        ["*.cc"],
        exclude = [
            "**/*_test.cc",
            "**/*_benchmark.cc",
        ],
    ),
    hdrs = glob(
        ["*.h"],
        exclude = ["**/*_test_utils.h"],
    ),
    deps = [
        "//src/carnot/exec/ml:cc_library",
        "//src/carnot/funcs/builtins/sql_parsing:cc_library",
        "//src/carnot/udf:cc_library",
        "@com_github_derrickburns_tdigest//:tdigest",
        "@com_github_google_sentencepiece//:libsentencepiece",
        "@com_github_grpc_grpc//:grpc++",
        "@com_github_uriparser_uriparser//:uriparser",
        "@com_googlesource_code_re2//:re2",
    ],
)

pl_cc_test(
    name = "collections_test",
    srcs = ["collections_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "conditionals_test",
    srcs = ["conditionals_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "math_sketches_test",
    srcs = ["math_sketches_test.cc"],
    # TODO(zasgar): PL-440 Fix ASAN/TSAN issues with tdigest code.
    tags = [
        "no_asan",
        "no_tsan",
    ],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "math_ops_test",
    srcs = ["math_ops_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "json_ops_test",
    srcs = ["json_ops_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "string_ops_test",
    srcs = ["string_ops_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "ml_ops_test",
    srcs = ["ml_ops_test.cc"],
    args = [
        "--sentencepiece_dir=$(location //:sentencepiece.proto)",
        "--embedding_dir=$(location //:embedding.proto)",
    ],
    data = [
        "//:embedding.proto",
        "//:sentencepiece.proto",
    ],
    deps = [
        ":cc_library",
        "//src/carnot/exec/ml:eigen_testutils",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_binary(
    name = "ml_ops_benchmark",
    testonly = 1,
    srcs = ["ml_ops_benchmark.cc"],
    args = [
        "--sentencepiece_dir=$(location //:sentencepiece.proto)",
        "--embedding_dir=$(location //:embedding.proto)",
    ],
    data = [
        "//:embedding.proto",
        "//:sentencepiece.proto",
    ],
    deps = [
        ":cc_library",
        "//src/common/benchmark:cc_library",
        # "@org_tensorflow//tensorflow/lite:tflite_with_xnnpack",
    ],
)

pl_cc_test(
    name = "request_path_ops_test",
    srcs = [
        "request_path_ops_test.cc",
        "request_path_ops_test_utils.h",
    ],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "sql_ops_test",
    srcs = ["sql_ops_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "regex_ops_test",
    srcs = ["regex_ops_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "pii_ops_test",
    srcs = ["pii_ops_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_binary(
    name = "pii_ops_benchmark",
    testonly = 1,
    srcs = ["pii_ops_benchmark.cc"],
    deps = [
        ":cc_library",
        "//src/common/benchmark:cc_library",
    ],
)

pl_cc_test(
    name = "uri_ops_test",
    srcs = ["uri_ops_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
    ],
)

pl_cc_test(
    name = "util_ops_test",
    srcs = ["util_ops_test.cc"],
    deps = [
        ":cc_library",
        "//src/carnot/udf:udf_testutils",
        "@com_github_grpc_grpc//:grpc++",
    ],
)
